package com.example.b_308.myapplication.comment.base;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;


/**
 * Created by  tongkang on  2017/4/8.
 */
public class WorkAndroidService extends Service {

    private static WorkAndroidService instance = null;
    private WorkUIService workUIService;

    /**
     * get the Service instance, if service is not started, return null.
     *
     * @return
     */
    public static WorkAndroidService getInstance() {
        return instance;
    }

    public static boolean isServiceStarted() {
        return instance != null;
    }


    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


    @Override
    public void onCreate() {
        instance = this;
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        try {
            if (null == workUIService) {
                workUIService = WorkUIService.getInstance();
                workUIService.start(getApplicationContext());
            }
        } catch (Exception e) {

        }
        return super.onStartCommand(intent, flags, startId);
    }


    @Override
    public void onDestroy() {
        try {
            if (null != workUIService)
                workUIService.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        instance = null;
    }

}
